{include file="public/header" /}
<style>
    .inputnickname{
        color: var(--c9);
        text-align: right;
    }
</style>
<body>
<div class="header">
    <i class="layui-icon layui-icon-left" ></i> 个人资料
</div>

<div class="personal-news flex-center">
    <label for="check">
        <p class="flex-center">
            <img src="{if $user.photo}{$user.photo}{else}cache('system')['default_photo']{/if}" alt=""  id="photo">
        </p>
        <p>点击更换头像</p>
    </label>
</div>

<ul class="set-list">
    <li>
        <a href="javascript:;">姓名
            <div>
                <input type="text" value=" {$user.nickname??''}" class="inputnickname" />
            </div>
        </a>
    </li>
    <li>
        <a href="javascript:;">手机号
            <div>{$user.mobile}
                <i class="layui-icon layui-icon-right"></i>
            </div>
        </a>
    </li>
    <li>
        <a href="">推荐人ID
            <div>{$user.parent_code ?? '-'}
<!--                <i class="layui-icon layui-icon-right"></i>-->
            </div>
        </a>
    </li>

</ul>
</body>
{include file="public/footer"/}
<script>
    $('.inputnickname').blur('input', debounce(function() {
        $.post("{:url('edit')}",{nickname:$(".inputnickname").val()},function(data,status){
            layer.msg(data.msg, {time: 1000}, function () {
                window.location.reload();
            });
        });
    }, 1000));
    /**
     * 防抖函数
     */
     function debounce(func, wait, immediate) {
        var timeout;
        return function() {
            var context = this, args = arguments;
            var later = function() {
                timeout = null;
                if (!immediate) func.apply(context, args);
            };
            var callNow = immediate && !timeout;
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
            if (callNow) func.apply(context, args);
        };
    }
</script>
</html>